<?php

namespace App\Jobs\Finance\Traits;

trait CommonBranchBillTrait
{
    public function getBranchServicePeriod($servicePeriod){
        if(str_contains($servicePeriod,'-')){
            $period=explode('-',$servicePeriod);
            return [
                'start'=>$period[0],
                'end'=>$period[1],
            ];
        }
        return [];
    }
    //匹配部门报价
    public function selectQuoteFinal($departQuotePrice,$dayAverage){
        $quotes=json_decode($departQuotePrice,true);
        $final=0;
        if($quotes && is_array($quotes)){
            foreach ($quotes as $quote){
                if($quote['volume_start']=='' && $quote['volume_end']==''){
                    return $quote['price'];
                }
                if($dayAverage>$quote['volume_start'] && $dayAverage<=$quote['volume_end']){
                    return $quote['price'];
                }
                //匹配不上就用最后一行的
                $final=$quote['price'];
            }
            return $final;
        }
        return $final;
    }

}
